package fly

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type FlyDeviceBasic struct{
	gorm.Model
	Name string
	DeviceLocalID string
	LevelLocalID string
	CompanyID string
	Phone string 
	Email string 
	DeviceTypeID string
	AirportID string
	Identity string
	Longitude string
	Latitude string
	ClientIP string
	ClientPort string
	FromCompany string
	FromBrand string
	VideoID string
	VideoType string
	Salt string
	LoginTime time.Time
	IsLogout bool
	DeviceInfo string
	MaxHeight string
	MaxSpeed string
 }

 func (table *FlyDeviceBasic) TableName() string {

	return "fly_device_basic"
}

func GetFlyDeviceBasicList() []*FlyDeviceBasic { 
	data := make([]*FlyDeviceBasic,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindFlyDeviceBasicByName(name string) FlyDeviceBasic {
	user := FlyDeviceBasic{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindFlyDeviceBasicByID(id uint) FlyDeviceBasic {
	user := FlyDeviceBasic{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func FindFlyDeviceByTypeIDAndCompanyID(id string,CompanyID string) []*FlyDeviceBasic {
	user := make([]*FlyDeviceBasic,100)
	utils.DB.Where("level_local_id = ? and company_id = ?",id,CompanyID).Find(&user)
	return user
}

func CreateFlyDeviceBasic(user FlyDeviceBasic) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteFlyDeviceBasic(user FlyDeviceBasic) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateFlyDeviceBasic(user FlyDeviceBasic) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(FlyDeviceBasic{Name: user.Name, DeviceTypeID: user.DeviceTypeID,Longitude: user.Longitude, Latitude: user.Latitude,VideoID: user.VideoID ,VideoType: user.VideoType ,FromCompany: user.FromCompany,FromBrand: user.FromBrand, AirportID: user.AirportID, MaxHeight: user.MaxHeight, MaxSpeed: user.MaxSpeed, DeviceInfo: user.DeviceInfo})
}